package com.ygsj.Utils;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.logging.Handler;



public class WebServiceUtils {
    private WebServiceUtils(){}
    private static class Holder{
        private static final WebServiceUtils webServiceUtils = new WebServiceUtils();
    }
    public static WebServiceUtils getInstance(){
        return Holder.webServiceUtils;
    }
    /*以上单例*/

    /*请求封装*/
    public SoapObject startWebservice(String namespace,String methodName,String endPoint,String soapAction){
        SoapObject soapObject = new SoapObject(namespace, methodName);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER12);
        envelope.bodyOut = soapObject;
        //envelope.dotNet = true;
        envelope.setOutputSoapObject(soapObject);
        HttpTransportSE transport = new HttpTransportSE(endPoint);

        try {
            transport.call(soapAction, envelope);
        }catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }

        // 获取返回的数据
        SoapObject object = (SoapObject) envelope.bodyIn;
        return  object;
    }

}
